home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / FILER / TARSRC.SPK / c / options < prev    next >
Text File  |  1994-09-13  |  4KB  |  202 lines

  1. #include <ctype.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "tar.h"
  5. #include "options.h"
  6.  
  7.  
  8. static void SetDevice(char **cp) {
  9.   if (!UnixArchive)
  10.     MultipleVolumes = 1;
  11.   driveno = **cp - '0';
  12.   switch (*(*cp + 1)) {
  13.     case 'D':
  14.     case 'E':
  15.     case 'F':
  16.     case 'L':
  17.     case 'M':
  18.     case 'Q':
  19.     case 'H':
  20.     case 'N':
  21.       format = *(++*cp);
  22.       break;
  23.     default:
  24.       fprintf(stderr, "tar: %c: unknown disc format\n", *(*cp + 1));
  25.       Terminate(25);
  26.   }
  27. } /* SetDevice */
  28.  
  29.  
  30. static tapedevice_t CheckDevNames(char *TestName) {
  31.   char *cp;
  32.   char lowername[256];
  33.  
  34.   cp = lowername;
  35.   while (*TestName) {
  36.     *cp++ = toupper(*TestName++);
  37.   }
  38.   if (strncmp(lowername, "RMT:", 4) == 0) {
  39.     return tapedevice_RMT;
  40.   }
  41.   if (strncmp(lowername, "FLOPPY:", 7) != 0) {
  42.     return tapedevice_FILE;
  43.   }
  44.   if (lowername[7] != '0' && lowername[7] != '1') {
  45.     return tapedevice_FILE;
  46.   }
  47.   cp = lowername + 7;
  48.   SetDevice(&cp);
  49.   return tapedevice_DISC;
  50. } /* CheckDevNames */
  51.  
  52.  
  53. int CheckOption(char **cp, char *next) {
  54.   int NextCnt;
  55.  
  56.   NextCnt = 0;
  57.   switch(**cp) {
  58.     case ' ':
  59.     case '-':
  60.       break;
  61.     case '0':
  62.     case '1':
  63.     case '2':
  64.     case '3':
  65.       fprintf(stderr,
  66. "tar: warning: obsolete option '%c' use 'f' with device name instead\n",**cp);
  67.       SetDevice(cp);
  68.       break;
  69.     case 'b':
  70.       if (next == NULL) {
  71.         fprintf(stderr,"tar: blocksize must be specified with 'b' option\n");
  72.         usage();
  73.       }
  74.       nblock = atoi(next);
  75.       if (nblock <= 0) {
  76.         fprintf(stderr,"tar: invalid blocksize \"%s\"\n",next);
  77.         Terminate(7);
  78.       }
  79.       NextCnt++;
  80.       break;
  81.     case 'c':
  82.       CreateArchive = 1;
  83.       AppendToArchive = 1;
  84.       break;
  85.     case 'e':
  86.       if (next == NULL) {
  87.         fprintf(stderr,"tar: extension length must be specified with 'e' option\n");
  88.         usage();
  89.       }
  90.       MaxExtLength = atoi(next);
  91.       NextCnt++;
  92.       break;
  93.     case 'f':
  94.       if (next == NULL) {
  95.         fprintf(stderr,"tar: tapefile must be specified with 'f' option\n");
  96.         usage();
  97.       }
  98.       tapedevice = CheckDevNames(next);
  99.       switch (tapedevice) {
  100.         case tapedevice_FILE:
  101.           ArchiveName = next;
  102.           break;
  103.         case tapedevice_RMT:
  104.           ArchiveName = next + 4;
  105.           break;
  106.       }
  107.       ArchiveFileSpecified = 1;
  108.       NextCnt++;
  109.       break;
  110.     case 'i':
  111.       IgnoreArchiveErrors = 1;
  112.       break;
  113.     case 'l':
  114.       UseListFile = 1;
  115.       if (next != NULL) {
  116.         listfile = next;
  117.         NextCnt++;
  118.       }
  119.       break;
  120.     case 'm':
  121.       DoNotExtractFileDates = 1;
  122.       break;
  123.     case 'p':
  124.       ConvertExclamationMark = 1;
  125.       break;
  126.     case 'r':
  127.       AppendToArchive = 1;
  128.       break;
  129.     case 's':
  130.       SwapExtensionToDir = 1;
  131.       break;
  132.     case 't':
  133.       ListArchivesContents = 1;
  134.       break;
  135.     case 'v':
  136.       Verbose = 1;
  137.       break;
  138.     case 'w':
  139.       ConfirmActions = 1;
  140.       break;
  141.     case 'x':
  142.       ExtractFromArchive = 1;
  143.       break;
  144.     case 'z':
  145.       CompressFiles = 1;
  146.       break;
  147.     case 'B':
  148.       Reblock = 1;
  149.       break;
  150.     case 'E':
  151.       PeriodSlashConversion = 1;
  152.       break;
  153.     case 'F':
  154.       FormatFloppies = 1;
  155.       break;
  156.     case 'M':
  157.       MultipleVolumes = 1;
  158.       break;
  159.     case 'L':
  160.       if (next == NULL) {
  161.         fprintf(stderr,"tar: maximum leaf length must be specified with 'L' option\n");
  162.         usage();
  163.       }
  164.       MaxLeafLength = atoi(next);
  165.       NextCnt++;
  166.       break;
  167.     case 'O':
  168.       NoDiskDestroyConfirmation = 1;
  169.       break;
  170.     case 'P':
  171.       UseCanonicalisedPaths = 1;
  172.       break;
  173.     case 'Q':
  174.       QuietExecution = 1;
  175.       break;
  176.     case 'S':
  177.       SwapInWholePath = 1;
  178.       break;
  179.     case 'T':
  180.       CommaFileTypes = 1;
  181.       break;
  182.     case 'U':
  183.       UnixArchive = 1;
  184.       MultipleVolumes = 0;
  185.       break;
  186.     case 'V':
  187.       VeryVerbose = 1;
  188.       Verbose = 1;
  189.       break;
  190.     case 'X':
  191.       AddFileTypeExtension = 1;
  192.       break;
  193.     case 'Z':
  194.       ConvertCompressExtension = 1;
  195.       break;
  196.     default:
  197.       fprintf(stderr, "tar: %c: unknown option\n", **cp);
  198.       usage();
  199.   }
  200.   return NextCnt;
  201. } /* CheckOption */
  202.